// Decompiled by Jad v1.5.8g. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.kpdus.com/jad.html
// Decompiler options: packimports(3) definits fieldsfirst ansi space safe 
// Source File Name:   BumpSensorView.java

package jones.gui;

import java.awt.*;
import java.util.Observable;
import java.util.Observer;
import javax.swing.JPanel;
import jones.SimpleRobot;

public class BumpSensorView extends JPanel
    implements Observer
{

    private static final int OVAL_MARGIN = 10;
    private int bumpCount = 0;

    public BumpSensorView()
    {
        bumpCount = 0;
    }

    public void update(Observable obs, Object obj)
    {
        SimpleRobot robot = (SimpleRobot)obs;
        setBumping(robot.isBumping());
        repaint();
    }

    private synchronized void setBumping(boolean isBumping)
    {
        if (isBumping)
            bumpCount++;
    }

    private synchronized boolean isBumping()
    {
        if (bumpCount > 0)
        {
            bumpCount--;
            return true;
        } else
        {
            return false;
        }
    }

    public void paintComponent(Graphics g)
    {
        super.paintComponent(g);
        Dimension size = getSize();
        g.setColor(Color.black);
        g.drawOval(10, size.height / 2, size.width - 20, size.height);
        if (isBumping())
        {
            g.setColor(Color.red);
            g.fillOval(10, size.height / 2, size.width - 20, size.height);
        }
    }
}
